package com.itheima.blog.admin.service.impl;

import com.itheima.api.client.dto.CategoryDto;
import com.itheima.blog.admin.dao.CategoryMapper;
import com.itheima.blog.admin.entity.Category;
import com.itheima.blog.admin.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 博客分类表 服务实现类
 * </p>
 *
 * @author cccg
 * @since 2023-07-12
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public List<Category> getCategoryAllList() {
        return this.list();
    }

    @Override
    public CategoryDto getCategoryByName(String categoryName) {
        Category category = lambdaQuery().eq(Category::getName, categoryName).one();
        CategoryDto categoryDto = new CategoryDto();
        categoryDto.setName(category.getName());
        categoryDto.setId(category.getId());
        return categoryDto;
    }
}
